Can Solidity smart contracts store a huge amount of data in the

contracts? No, because the storage capacity is limited and also the

storing of data on a contract needs a lot of cost in terms of the

consumption of gas. Hence, we must write the code judiciously, and

hence, we need to have a good idea on the data storing mechanism

in EVM.

The EVM uses four different types of memory locations to save the

associated data in a smart contract. They are Storage, Memory,

Calldata, and Stack.

2.5.13.1 Storage

Storage is the area where all the state variables are stored.

It’s the permanent memory associated with each account where the

data is stored in the key value pair. Every Ethereum account has the

access only to its own Storage, where it can store and retrieve data.

Refer to the following code:

// SPDX-License-Identifier: SOME IDENTIFIER

pragma solidity ^0.8.10;

contract StorageContract {

uint varStorage1;

uint varStorage2;

function saveInStorage() public {

varStorage1 = 10;

varStorage2 = 20;

}

}

The cost of gas is the maximum when associated with the data in

Storage. Hence, we need to write the code in such a way that the

number of state variables are minimum to save the associated gas

cost.

2.5.13.2 Memory